package thirdlyHomework;

import java.util.Random;

public class method2 {
    public  static char[] test2() {
        char[] ch = new char[62];
        int index = 0;
        // 将A-Z a - z 存储到chs数组中
        for (char c = 'A'; c <= 'Z'; c++) {
            ch[index++] = c;
        }
        for (char c = 'a'; c <= 'z'; c++) {
            ch[index++] = c;
        }
        for (char c = '0'; c <= '9'; c++) {
            ch[index++] = c;
        }
        return ch;

    }


    public static String getStr(){
        // 获取字符数组
        char[] ch = test2();
        // 创建Random对象
        Random r = new Random();
        // 创建StringBuilder对象
        StringBuilder sb = new StringBuilder();

        // 循环5次，随机5个字符
        for (int i = 0; i < 5; i++) {
            // 0 ~ 数组长度-1
            // 随机获取索引的值
            int index = r.nextInt(ch.length);
            char c = ch[index];

            // 添加到sb中
            sb.append(c);
        }
        // 将sb转换成String并返回
        return sb.toString();
    }

}
